/*
 * Created by SharpDevelop.
 * User: Tivadar Papai
 * Date: 10/11/2007
 * Time: 10:53 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;
using RoverStudio.Math;

namespace RoverStudio.Common.WorldModel
{
    /// <summary>
    /// Description of Path.
    /// </summary>
    public class Path : CreatedObject
    {
        private CaterpillarVehicle rover;

        public CaterpillarVehicle Rover
        {
            get { return rover; }
            set { rover = value; }
        }

        private int selectedPathElementIndex;

        public int SelectedPathElementIndex
        {
            get { return selectedPathElementIndex; }
            set { 
                if (value < this.PathElements.Count)
                    selectedPathElementIndex = value;
            }
        }


        private List<Vector3D> pathElements = new List<Vector3D>();

        public List<Vector3D> PathElements
        {
            get { return pathElements; }
        }

        public Path(WorldModel worldModel)
            : base(null, worldModel)
        {
        }

        public void CreateNewPath()
        {
            this.selectedPathElementIndex = -1;
            this.pathElements.Clear();
            WorldModel.ObjectsChanged(this, new WorldModelObjectEventArgs(this, DateTime.Now));
        }

        public void AddPathNodes(params Vector3D[] nodes)
        {
            foreach (Vector3D v in nodes)
            {
                this.pathElements.Add(v);
            }
            WorldModel.ObjectsChanged(this, new WorldModelObjectEventArgs(this, DateTime.Now));
        }

        public void RemoveLast()
        {
            if (this.pathElements.Count == 0)
                return;
            this.pathElements.RemoveAt(this.pathElements.Count - 1);
            if (this.selectedPathElementIndex == this.pathElements.Count - 1)
                this.selectedPathElementIndex--;
            WorldModel.ObjectsChanged(this, new WorldModelObjectEventArgs(this, DateTime.Now));
        }

    }
}
